home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / gfx / show / gs_src_gs.lha / gs5.03 / gxdevmem.h < prev    next >
C/C++ Source or Header  |  1997-03-26  |  7KB  |  151 lines

  1. /* Copyright (C) 1989, 1995, 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gxdevmem.h */
  20. /* "Memory" device structure for Ghostscript library */
  21. /* Requires gxdevice.h */
  22.  
  23. /*
  24.  * A 'memory' device is essentially a stored bitmap.
  25.  * There are several different kinds: 1-bit black and white,
  26.  * 2-, 4-, and 8-bit mapped color, 16- and 24-bit RGB color,
  27.  * and 32-bit CMYK color.  (16-bit uses 5/6/5 bits per color.)
  28.  * All use the same structure, since it's so awkward to get the effect of
  29.  * subclasses in C.
  30.  *
  31.  * Memory devices come in two flavors: standard, which always stores bytes
  32.  * big-endian, and word-oriented, which stores bytes in the machine order
  33.  * within 32-bit "words".  The source data for copy_mono and
  34.  * copy_color must be in big-endian order, and since memory devices
  35.  * also are guaranteed to allocate the bitmap consecutively,
  36.  * the bitmap of a standard memory device can serve directly as input
  37.  * to copy_mono or copy_color operations.  This is not true of word-oriented
  38.  * memory devices, which are provided only in response to a request by
  39.  * a customer with their own image processing library that uses this format.
  40.  */
  41. #ifndef gx_device_memory_DEFINED
  42. #  define gx_device_memory_DEFINED
  43. typedef struct gx_device_memory_s gx_device_memory;
  44. #endif
  45.  
  46. struct gx_device_memory_s {
  47.     gx_device_forward_common;    /* (see gxdevice.h) */
  48.     gs_matrix initial_matrix;    /* the initial transformation */
  49.     uint raster;            /* bytes per scan line, */
  50.                     /* filled in by 'open' */
  51.     bool foreign_bits;        /* if true, bits are not in */
  52.                     /* GC-able space */
  53.     byte *base;
  54.     byte **line_ptrs;        /* scan line pointers */
  55. #define scan_line_base(dev,y) ((dev)->line_ptrs[y])
  56.     /* If the bitmap_memory pointer is non-zero, it is used for */
  57.     /* allocating the bitmap when the device is opened, */
  58.     /* and freeing it when the device is closed. */
  59.     gs_memory_t *bitmap_memory;
  60.         /* Following is used for mapped color, */
  61.         /* including 1-bit devices (to specify polarity). */
  62.     gs_const_string palette;    /* RGB triples */
  63.         /* Following is only used for 24-bit color. */
  64.     struct _c24 {
  65.         gx_color_index rgb;    /* cache key */
  66.         bits32 rgbr, gbrg, brgb;    /* cache value */
  67.     } color24;
  68.         /* Following are only used for alpha buffers. */
  69.         /* The client initializes those marked with $; */
  70.         /* they don't change after initialization. */
  71.     gs_log2_scale_point log2_scale;    /* $ oversampling scale factors */
  72.     int log2_alpha_bits;    /* $ log2 of # of alpha bits being produced */
  73.     int mapped_x;        /* $ X value mapped to buffer X=0 */
  74.     int mapped_y;        /* lowest Y value mapped to buffer */
  75.     int mapped_height;    /* # of Y values mapped to buffer */
  76.     int mapped_start;    /* local Y value corresponding to mapped_y */
  77.     gx_color_index save_color;    /* last (only) color displayed */
  78. };
  79. extern_st(st_device_memory);
  80. #define public_st_device_memory() /* in gdevmem.c */\
  81.   gs_public_st_composite(st_device_memory, gx_device_memory,\
  82.     "gx_device_memory", device_memory_enum_ptrs, device_memory_reloc_ptrs)
  83. #define st_device_memory_max_ptrs (st_device_forward_max_ptrs + 2)
  84. #define mem_device_init_private\
  85.     { identity_matrix_body },    /* initial matrix (filled in) */\
  86.     0,            /* raster (filled in) */\
  87.     true,            /* foreign_bits (default) */\
  88.     (byte *)0,        /* base (filled in) */\
  89.     (byte **)0,        /* line_ptrs (filled in by mem_open) */\
  90.     0,            /* bitmap_memory */\
  91.     { (byte *)0, 0 },    /* palette (filled in for color) */\
  92.     { gx_no_color_index },    /* color24 */\
  93.     { 0, 0 }, 0,        /* scale, log2_alpha_bits */\
  94.     0, 0, 0, 0,        /* mapped_* */\
  95.     gx_no_color_index    /* save_color */
  96.  
  97. /*
  98.  * Memory devices may have special setup requirements.
  99.  * In particular, it may not be obvious how much space to allocate
  100.  * for the bitmap.  Here is the routine that computes this
  101.  * from the width and height.
  102.  */
  103. ulong gdev_mem_data_size(P3(const gx_device_memory *, int, int));
  104. #define gdev_mem_bitmap_size(mdev)\
  105.   gdev_mem_data_size(mdev, (mdev)->width, (mdev)->height)
  106. /*
  107.  * Do the inverse computation: given the device width and a buffer size,
  108.  * compute the maximum height.
  109.  */
  110. int gdev_mem_max_height(P3(const gx_device_memory *, int, ulong));
  111. /*
  112.  * Compute the raster (data bytes per line) similarly.
  113.  */
  114. #define gdev_mem_raster(mdev)\
  115.   gx_device_raster((const gx_device *)(mdev), true)
  116.  
  117. /* Determine the appropriate memory device for a given */
  118. /* number of bits per pixel (0 if none suitable). */
  119. const gx_device_memory *gdev_mem_device_for_bits(P1(int));
  120.  
  121. /* Determine the word-oriented memory device for a given depth. */
  122. const gx_device_memory *gdev_mem_word_device_for_bits(P1(int));
  123.  
  124. /* Make a memory device. */
  125. /* mem is 0 if the device is temporary and local, */
  126. /* or the allocator that was used to allocate it if it is a real object. */
  127. /* page_device is 1 if the device should be a page device, */
  128. /* 0 if it should propagate this property from its target, or */
  129. /* -1 if it should not be a page device. */
  130. void gs_make_mem_mono_device(P3(gx_device_memory *mdev, gs_memory_t *mem,
  131.                 gx_device *target));
  132. void gs_make_mem_device(P5(gx_device_memory *mdev,
  133.                const gx_device_memory *mdproto,
  134.                gs_memory_t *mem, int page_device,
  135.                gx_device *target));
  136. void gs_make_mem_abuf_device(P6(gx_device_memory *adev, gs_memory_t *mem,
  137.                 gx_device *target,
  138.                 const gs_log2_scale_point *pscale,
  139.                 int alpha_bits, int mapped_x));
  140. void gs_make_mem_alpha_device(P4(gx_device_memory *adev, gs_memory_t *mem,
  141.                  gx_device *target, int alpha_bits));
  142.  
  143. /* Define whether a monobit memory device is inverted (black=1). */
  144. void gdev_mem_mono_set_inverted(P2(gx_device_memory *mdev, bool black_is_1));
  145.  
  146. /* Test whether a device is a memory device. */
  147. bool gs_device_is_memory(P1(const gx_device *));
  148.  
  149. /* Test whether a device is an alpha-buffering device. */
  150. bool gs_device_is_abuf(P1(const gx_device *));
  151.